﻿using Autodesk.AutoCAD.DatabaseServices;

namespace Galaxy.AutoCAD.Databases
{
    public static class ModelSpaceTool
    {
        #region 添加实体到文档的模型空间（定义为database的括展函数）
        public static ObjectId AddToModelSpace(this Database db, Entity ent)
        {
            ObjectId result;
            using (Transaction tran = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                result = btr.AppendEntity(ent);
                tran.AddNewlyCreatedDBObject(ent, true);
                tran.Commit();
            }
            return result;
        }
        #endregion
    }
}
